// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import Size = cc.Size;

const {ccclass, property} = cc._decorator;

@ccclass
export default class physicsBound extends cc.Component {

    onLoad () {
        let width   = cc.winSize.width || this.node.width;
        let height  = cc.winSize.height || this.node.height;

        let node = new cc.Node();
        node.group = "default";

        let body = node.addComponent(cc.RigidBody);
        body.type = cc.RigidBodyType.Static;
        body.bullet = true;

        this._addBound(node, 0, height/2, width, 20);
        this._addBound(node, 0, -height/2 , width, 20);
        this._addBound(node, -width/2 , 0, 20, height);
        this._addBound(node, width/2 , 0, 20, height);

        node.parent = this.node;
    }

    _addBound (node, x, y, width, height) {
        let collider = node.addComponent(cc.PhysicsBoxCollider);
        collider.offset.x = x;
        collider.offset.y = y;
        collider.size.width = width;
        collider.size.height = height;
    }
}
